// 密码数字+字母验证
export function validPsw(password,min = 6,max = 16) {  
    var num = 0;  
    var number = 0 ;  
    var letter = 0 ;  
    var bigLetter = 0 ;  
      
    if (password.search(/[0-9]/) != -1) {  
        num += 1;  
        number =1;  
    }  
    if (password.search(/[A-Z]/) != -1) {  
        num += 1;  
        bigLetter = 1 ;  
    }  
    if (password.search(/[a-z]/) != -1) {  
        num += 1;  
        letter = 1 ;  
    }  
    if(password.length < min || password.length > max){
        return false
    }
    if(number>=1&&(bigLetter+letter<=0)){  
        return false
    }  
    if(number==0&&(bigLetter+letter>=1)){
        return false
    }
    var reg = /^[0-9a-zA-Z]+$/;
    if(!reg.test(password)){
        return false
    }
    return true
} 

import { userAgent } from './types'
// 判断手机终端信息
export function getUserAgent(){
    var u = navigator.userAgent
    if(u.indexOf('MicroMessenger') != -1){
        return userAgent.WECHAT;
    }else if(!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)){
        return userAgent.IOS;
    }else if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1 || u.indexOf('Adr') > -1){
        return userAgent.ANDROID;
    }else{
        return userAgent.ANDROID;
    }
}

// 获取日期
export function getDate(day){
    if(!day){
        day = 0
    }
    const date = new Date()
    const newDate = new Date(date.getTime() - (day * 24 * 3600 * 1000));
    let newDateStr = newDate.getFullYear() + '-' + (newDate.getMonth() < 10 ? ( '0' + (newDate.getMonth() + 1)) : (newDate.getMonth() + 1)) + '-' + (newDate.getDate() < 10 ? ( '0' + (newDate.getDate())) : (newDate.getDate() ))
    return newDateStr
}